package gases.as3.librarys.compnents.swf
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	
	import gases.as3.librarys.compnents.events.SkinEvent;
	import gases.as3.librarys.compnents.resource.MacroResourceManagaers;
	import gases.as3.librarys.compnents.skin.SkinStylesMangaer;
	import gases.as3.librarys.compnents.skin.SkinTransform;
	import gases.as3.librarys.compnents.skin.data.BaseSkin;
	import gases.as3.librarys.compnents.skin.transform.TransformXML;

	public class StyleConfig extends EventDispatcher 
	{
		private static var _instance:StyleConfig;
		
		public function StyleConfig()
		{
			init();
		}
		
		/**
		 *获得单例 
		 * @return StyleConfig
		 * 
		 */		
		public static function get instance():StyleConfig
		{
			if(!_instance)
			{
				_instance = new StyleConfig();
			}
			return _instance;
		}
		
		public function get btnRedSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("red_btn") as BaseSkin;
		}
		
		public function get btnGreenSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("green_btn") as BaseSkin;
		}
		
		public function get btnScrollUpSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("scroll_up_btn") as BaseSkin;
		}
		
		public function get btnScrollDownSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("scroll_down_btn") as BaseSkin;
		}
		
		public function get btnScrollSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("scroll_btn") as BaseSkin;
		}
		
		public function get btnScrollBgSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("scroll") as BaseSkin;
		}
		
		public function get panelSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("panel_image") as BaseSkin;
		}
		
		public function get titleSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("title_image") as BaseSkin;
		}
		
		public function get treeSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("tree_image") as BaseSkin;
		}
		
		public function get iconListSkin():BaseSkin
		{
			return SkinStylesMangaer.instance.getSkinData("icon_list") as BaseSkin;
		}
		
		
		private function init():void
		{
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			_loader.load(new URLRequest("assets/skin.swf"));
		}
		
		private function onComplete(e:Event):void
		{
			var swf:DisplayObject = LoaderInfo(e.target).content as DisplayObject;
			MacroResourceManagaers.instance.UIResManager.setUISkinSwf(swf);
			_transform = new SkinTransform();
			_transform.setConfigTransform(new TransformXML());
			
			addXMLConfig();
		}
		
		private function addXMLConfig():void
		{
			_transform.resloveSkinConfig(XMLConfig.BTN_GREEN_XML);
			_transform.resloveSkinConfig(XMLConfig.BTN_RED_XML);
			_transform.resloveSkinConfig(XMLConfig.ICON_LIST_XML);
			_transform.resloveSkinConfig(XMLConfig.PANEL_XML);
			_transform.resloveSkinConfig(XMLConfig.SCROLL_XML);
			_transform.resloveSkinConfig(XMLConfig.TITLE_XML);
			_transform.resloveSkinConfig(XMLConfig.TREE_XML);
			
			this.dispatchEvent(new SkinEvent(SkinEvent.LOAD_COMPLETE));
		}
		
		
		private var _loader:Loader;
		private var _transform:SkinTransform;
		private var _btnRedSkin:BaseSkin;
		
	}
}